package com.edu.exam.enums.student;

import com.edu.exam.enums.core.StatusEnum;

/**
 * 学籍状态枚举
 * 管理学生的学籍状态信息
 *
 * @author System
 * @version 2.0.0
 */
public enum EnrollmentStatus implements StatusEnum {

    /** 预注册 */
    PRE_ENROLLED("PRE_ENROLLED", "预注册"),

    /** 在读 */
    ENROLLED("ENROLLED", "在读"),

    /** 休学 */
    SUSPENDED("SUSPENDED", "休学"),

    /** 毕业 */
    GRADUATED("GRADUATED", "毕业"),

    /** 退学 */
    DROPPED_OUT("DROPPED_OUT", "退学");

    private final String code;
    private final String description;

    EnrollmentStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static EnrollmentStatus fromCode(String code) {
        if (code == null || code.trim().isEmpty()) {
            throw new IllegalArgumentException("Enrollment status code cannot be null or empty");
        }

        for (EnrollmentStatus value : values()) {
            if (value.getCode().equals(code)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown enrollment status code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果描述无效
     */
    public static EnrollmentStatus fromDescription(String description) {
        for (EnrollmentStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown enrollment status description: " + description);
    }

    @Override
    public String toString() {
        return this.code + "(" + this.description + ")";
    }
}
